<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- App favicon -->
    <link rel="shortcut icon" href="/assets/images/favicon.ico">

    <link href="/assets/plugins/jvectormap/jquery-jvectormap-2.0.2.css" rel="stylesheet">

    <!-- App css -->
    <link href="/assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="/assets/css/icons.css" rel="stylesheet" type="text/css" />
    <link href="/assets/css/metismenu.min.css" rel="stylesheet" type="text/css" />
    <link href="/assets/css/style.css" rel="stylesheet" type="text/css" />
    <!-- 引入vue cdn -->
	<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
	<!-- 引入axios cdn -->
	<script src="/app/vue/axios/axios.min.js"></script>
    <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
</head>

<body data-type="index">

    <div class="row" style="padding-left:30px;padding-right:30px;">

        <div class="tpl-portlet-components">
            <div class="portlet-title">
                <div class="caption font-green bold">
                    <span class="am-icon-code"></span> 更新类别
                </div>
                <div class="tpl-portlet-input tpl-fz-ml">
                    <div class="portlet-input input-small input-inline">
                        <div class="input-icon right">

                        </div>
                    </div>
                </div>
            </div>
            <div class="tpl-block ">

                <div class="am-g tpl-amazeui-form">


                    <div class="am-u-sm-12 am-u-md-9">
                        <form class="am-form am-form-horizontal" id="vue_cates_edit" @submit.prevent="doEdit" @keyup.enter="doEdit">
                            <div class="am-form-group">
                                <label for="user-name" class="am-u-sm-3 am-form-label">类别名称</label>
                                <div class="am-u-sm-9">
                                    <input type="text" name="title" required placeholder="" v-model="title">
                                    <input type="hidden" name="id" v-model="id"/>
                                    <small></small>
                                </div>
                            </div>

                            <div class="am-form-group">
                                <div class="am-u-sm-9 am-u-sm-push-3">
                                    <button type="submit" class="am-btn am-btn-primary">保存数据</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <!-- jQuery  -->
    <script src="/assets/js/jquery.min.js"></script>
    <script src="/assets/js/bootstrap.bundle.min.js"></script>
    <script src="/assets/js/metisMenu.min.js"></script>
    <script src="/assets/js/waves.min.js"></script>
    <script src="/assets/js/jquery.slimscroll.min.js"></script>

    <script src="/assets/plugins/jvectormap/jquery-jvectormap-2.0.2.min.js"></script>
    <script src="/assets/plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>

    <script src="/assets/plugins/moment/moment.js"></script>
    <script src="/assets/plugins/apexcharts/apexcharts.min.js"></script>
    <script src="/assets/pages/jquery.dashboard.init.js"></script>
    <!-- App js -->
    <script src="/assets/js/app.js"></script>
    <script src="/source/scripts/window.js"></script>
    <script src="/source/js.js"></script>
    <script>
        $().ready(function () {
            $(".uploadImg").click(function () {
                openWindow("/upload.jsp");
            });
            $("#thumb").on("input", function () {
                $(".oldImg").attr("src", "/" + $("#thumb").val());
            });
        });
    </script>
    <script type="text/javascript">
        const baseUrl = "http://localhost:8080";
        let vm = new Vue({
            el: "#vue_cates_edit",
            data() {
                return {
                    title: "",
                    id: ""
                }
            },
            methods: {
                doEdit(){
                    // API：http://localhost:8080/hotel/cates/cates/update
                    // method：post
                    // data: title
                    axios({
                        url: baseUrl + "/hotel/cates/cates/update",
                        method: "post",
                        responseType: "json",
                        data: {
                            "title": this.title,
                            "id": this.id
                        }
                    }).then(response => {
                        // console.log("编辑成功：",response);
                        swal({
                            title: response.data.data.message,
                            text: "点击确定继续",
                            icon: response.data.data.state,
                            button: "确定",
                        }).then(value => {
                            window.location.href = baseUrl + "/" + response.data.data.url;
                        });
                    })
                },
                getEditData(){
                    let id = window.location.href.toString().split("=")[1];
                    axios({
                        method: "get",
                        url: baseUrl + "/hotel/cates/cates/get_update_data/" + id,
                        responseType: "json"
                    }).then(response => {
                        // console.log(response);
                        this.title = response.data.cates.title;
                        this.id = response.data.cates.id;
                    }).catch(error => {
                        console.log("请求失败，error信息：",error);
                    })
                }
            },
            created() {
                this.getEditData();
            },
        });
    </script>
</body>

</html>